<?php require_once(dirname(__FILE__) . '/inc/config.inc.php');
IsModelPriv('goodsorder');
require_once "function.php";
$id = htmlspecialchars($id);


/*
进度：
0 已经撤单
1 报修成功
2 客服已经联系
3 系统已经派单
4 工程师接单
5 维修完成
6 已经评价
*/

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>任务详情</title>
    <link href="templates/style/admin.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="templates/js/jquery.min.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="ui/css/bootstrap.min.css">
    <link rel="stylesheet" href="ui/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="templates/js/zoomify.min.css">
    <script language="javascript" type="text/javascript" src="DatePicker/WdatePicker.js"></script>
</head>

<body style="width:890px;">
<?php

$sql = "SELECT f.*,j.dataname as jinduname  FROM `#@__order` as f
		left join `#@__cascadedata`  as j on j.datavalue=f.jindu  
		WHERE j.datagroup='jindu'    AND    f.id='$id' ";


$row = $dosql->GetOne($sql);

$odernum = date("Ymd", $row['post_time']) . "-" . $row['id'];
$order_id = $row['id'];
//故障图片
$picurl_arr = explode(',', $row['picfiles']);
$pic_lists = "";
array_pop($picurl_arr);
for ($i = 0; $i < count($picurl_arr); $i++) {
    $pic_lists .= '<li class="example"><img src="' . $picurl_arr[$i] . '" width=120/></li>';
}

//完修图片
$over_picurl_arr = explode(',', $row['over_picurls']);
$over_pic_lists = "";
array_pop($over_picurl_arr);
for ($i = 0; $i < count($over_picurl_arr); $i++) {
    $over_pic_lists .= '<li class="example"><img src="' . $over_picurl_arr[$i] . '" width=120/></li>';
}

$jindu = intval($row['jindu']);

//位置信息
$address_lat = $row['latitude'];
$address_long = $row['longitude'];
if ($row['apply_address'] == "" && empty($row['poster'])) {
    $must_conv = "yes";
} else {
    $must_conv = "no";

}


?>
<h1 class="tit">任务详情</h1>
<div class="order_top">
    <div class="order_top1">单号：<?php echo $odernum; ?></div>
    <div class="order_top1 t_fr">创建日期：<?php echo date("Y年m月d日", $row['post_time']); ?>
        <?php if (!empty($row['poster'])) {
            echo "<b class='red'> 发布人：" . $row['poster'] . "</b>";
        } ?>
    </div>
</div>
<table width="200" border="1" class="table table-bordered">
    <tr>
        <td width="100">单位：</td>
        <td><?php echo $row['school']; ?></td>
        <td width="100">联系人：</td>
        <td><?php echo $row['truename'] . "    " . $row['mobile']; ?></td>
    </tr>
    <tr>
        <td>地址：</td>
        <td><?php echo $row['address'] ?></td>
        <td>位置信息：</td>
        <td id="apply_address_info"><?php if (empty($row['poster'])) {
                echo $row['apply_address'] . "<br/>位置描述：" . $row['apply_address_name'];
            } else {
                echo "商务直接派单，不显示位置信息";
            } ?></td>
    </tr>
    <tr>
        <td>服务类型</td>
        <td><?php echo getTypeNameFromTask($row['apply_type']); ?></td>
        <td>设备类型：</td>
        <td><?php echo getRepairMode($row['apply_device']) ?>
            <?php
            if (!empty($row['device_num'])) {
                echo "<b class='red'>序列号：" . $row['device_num'] . "</b>";
                $sn_num = $row['device_num'];
                $row_sn = $dosql->GetOne("SELECT * FROM `#@__sn` WHERE `sn`='$sn_num' ");
                if (is_array($row_sn) && isset($row_sn['id'])) {
                    // 过期时间
                    $guoqi = $row_sn['end_time'] + 86400;
                    if (time() > $guoqi) {
                        echo '<span class="label label-danger mr-5">过保</span>';
                    }
                }
            }
            ?></td>
    </tr>
    <tr class="red">
        <td>执行人：</td>
        <td colspan="3"><?php
            if (!empty($row['manageid'])) {
                $m_str = $row['manageid'];
                $m_arr = explode(",", $m_str);
                foreach ($m_arr as $key => $val) {
                    echo ' <i class="glyphicon glyphicon-user"></i>      ' . getManage($val);
                }

            }

            ?></td>
    </tr>
    <tr class="">
        <td>任务时间：</td>
        <td colspan="3">
            <i class="glyphicon glyphicon-off green"></i> <?php echo date("Y-m-d H:i:s", $row['begintime']) . "  <i  class=' red glyphicon glyphicon-random'></i>        " . date("Y-m-d H:i:s", $row['endtime']) ?>
        </td>
    </tr>
    <tr>
        <td>任务类型：</td>
        <td colspan="3">
            <i class="glyphicon glyphicon-briefcase blue"> </i> <?php echo getRepairMode($row['repairid']) ?>
            <i class="glyphicon glyphicon-usd red"></i>任务奖励：<b class="red"><?php echo $row['fee'] ?></b></td>
    </tr>
    <tr>
        <td>任务详情：</td>
        <td colspan="3"><?php echo $row['content'] ?></td>
    </tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0" id="ajaxlist" class="dataTable table table-striped table-bordered">
    <tr height="50" align="left" class="head">
        <td width="3%">ID</td>
        <td width="10%">执行人</td>
        <td width="10%">操作时间</td>
        <td width="10%">增加/减少</td>
        <td width="10%">事由</td>
        <td width="8%">任务奖励</td>
    </tr>
    <?php
    $sql_order = "SELECT f.* ,u.truename as truename  FROM `#@__fee_log` as f
		left join `#@__user`   as u on u.id=f.manageid
		WHERE   f.orderid='$id'    ORDER BY f.id desc ";
    $dosql->Execute($sql_order, 5);
    while ($row = $dosql->GetArray(5)) {
        if (intval($row['fee']) > 0) {
            $fee = '<span class="label label-danger">' . $row['fee'] . '</span>';
        } else {
            if ($row['jindu'] > 4) {
                $fee = '<span class="label label-success">免费</span>';
            } else {
                $fee = '';
            }
        }

        $tr_color = "";
        if ($row['op'] == 'add') {
            $op_str = '<i class=" red glyphicon glyphicon-plus">  增加</i>';
        } elseif ($row['op'] == 'move') {
            $op_str = '<i class="green glyphicon glyphicon-minus">  减少</i>';
            $tr_color = 'class="success"';
        }
        ?>
        <tr align="left" <?php echo $tr_color; ?> >
            <td><?php echo $row['id']; ?></td>
            <td><?php echo $row['truename']; ?></td>
            <td><?php echo date("Y-m-d H:i:s", $row['op_time']) ?></td>
            <td><?php echo $op_str; ?></td>
            <td><?php echo $row['remark']; ?></td>
            <td><?php echo $fee; ?></td>
        </tr>
    <?php } ?>
</table>
<?php if ($_SESSION['adminlevel'] == '1') { ?>
    <div class="lianxi_box" id="lianxi_box">
        <table width="100%" border="0" cellpadding="0" cellspacing="0" id="ajaxlist" class="dataTable table table-striped table-bordered">
            <tr>
                <td width="100">操作</td>
                <td width="200">
                    <input type="radio" name="op" id="op" value="add" checked="checked"/>
                    增加
                    <input type="radio" name="op" id="op" value="move"/>
                    减少
                </td>
                <td width="100">事项</td>
                <td width="200">
                    <select name="feetype" id="feetype" class="form-control">
                        <option value="0">请选择</option>
                        <?php
                        $dosql->Execute("SELECT * FROM `#@__cascadedata` WHERE `datagroup`='feetype' and fee='add' order by orderid ASC", 10);
                        while ($row = $dosql->GetArray(10)) {
                            echo '<option value="' . $row['datavalue'] . '" >' . $row['dataname'] . '</option>';

                        }
                        ?>
                    </select>

                </td>

            </tr>
            <tr>

                <td width="80"> 积分：</td>
                <td><input type="text" class="form-control w100" name="fee" id="fee"/>正整数</td>
                <td width="80"> 日期：</td>
                <td>
                    <input class="form-control w200 " name="date" id="date" type="text"
                           onClick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                           value="<?php echo date("Y-m-d H:i:s", time()) ?>">


                </td>
            </tr>
            <tr>
                <td>备注：</td>
                <td colspan="6">
                    <textarea class="form-control" name="remark" id="remark"></textarea>
                </td>
            </tr>
        </table>
        <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
            <button type="button" class="btn btn-primary send-confirm-btn" id="shenhe" onclick="jiangli(<?php echo $id; ?>)">
                提交
            </button>
        </div>
    </div>
    </div>
<?php } ?>
<script>
    $(function () {
        $("input[name = 'op']").change(function () {
            var opop=$(this).val();
            $.ajax({
                type: 'post',
                url: "getFeeType.php?op=" + opop,
                //data: {areaId:areaId},
                dataType: 'json',
                success: function (res) {
                    console.log(res.data);
                    $("#feetype").html("");
                    $("#feetype").html(res.data);
                }

            });

        });
    });

    function jiangli(id) {
        var _remark = $("#remark").val();
        var _date = $("#date").val();
        if (_remark == "") {
            layer.msg("请输入操作的备注");
            return false;
        }
        var _fee = $("#fee").val();
        if (_fee == "") {
            layer.msg("请输入奖励的金额");
            return false;
        }
        var _op = $("input[name='op']:checked").val();

        var feetype = $('#feetype option:selected').val();
        if (feetype == 0) {
            layer.msg("请选择积分操作的事由");
            return false;
        }

        $.ajax({
            type: 'POST',
            url: "op.php",
            data: {id: id, op: 'jiangli', 'fee': _fee, 'op_type': _op, 'remark': _remark, 'date': _date,"feetype":feetype},
            dataType: 'JSON',
            success: function (result) {
                console.log(result);
                if (result.errno == 0) {
                    console.log(result.msg);
                    if (result.msg === "ok") {
                        $(".lianxi_box").hide();
                        layer.alert('积分操作成功', {
                            skin: 'layui-layer-molv' //样式类名
                            , closeBtn: 0
                        }, function () {
                            window.location.reload();
                        });


                    } else {
                        layer.msg('操作失败');
                    }
                }
            }
        });

    }

    function paidan(id, type) {
        var checkids = [];
        $("input[name='manageid']:checked").each(function (i) {
            checkids[i] = $(this).val();
        });
        var _manageid = checkids;
        var _beginTime = $("#beginTime").val();
        var _endTime = $("#endTime").val();
        var _remark = $("#remark").val();
        var _repairid = $("#repairid").val();
        if (_repairid == '-1') {
            layer.msg('请选择任务类型');
            return false;
        }
        if (_manageid.length == '0') {
            layer.msg('请选择工程师');
            return false;
        }
        $.ajax({
            type: 'POST',
            url: "op.php",
            data: {
                id: id,
                op: 'paidan',
                manageid: _manageid,
                type: type,
                remark: _remark,
                beginTime: _beginTime,
                endTime: _endTime,
                repairid: _repairid
            },
            dataType: 'JSON',
            success: function (result) {
                console.log(result);
                if (result.errno == 0) {
                    console.log(result.msg);
                    if (result.msg === "ok") {
                        $(".paidan_box").hide();
                        layer.msg('派单成功');
                        window.location.reload();

                    } else {
                        layer.msg('派单失败');
                    }
                }
            }
        });

    }


</script>
<script src="templates/js/zoomify.min.js"></script>
<script type="text/javascript">
    $('.example img').zoomify();
</script>
</body>
</html>